﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loki.Model
{
    public class LinkEqualityComparer<TEntityKey> : EqualityComparer<IEntityLink<TEntityKey>>
    {
        public override bool Equals(IEntityLink<TEntityKey> x, IEntityLink<TEntityKey> y)
        {
            if (x == null || y == null)
                return x == null;
            else
            {
                return Object.Equals(x.Left, y.Left) && Object.Equals(x.Right, y.Right);
            }
        }

        public override int GetHashCode(IEntityLink<TEntityKey> obj)
        {
            if (obj.Left == null && obj.Left == null)
            {
                return 0;
            }
            else if (obj.Right == null)
            {
                return obj.Left.GetHashCode();
            }
            else
            {
                return obj.Left.GetHashCode() ^ obj.Right.GetHashCode();
            }
        }
    }
}